package com.chisheng.caa.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chisheng.caa.pojo.entity.Major;

import java.util.Objects;

/**
 * 专业表 Mapper 映射
 */
public interface MajorMapper extends BaseMapper<Major> {

    /**
     * 返回专业名称对应的 ID 值
     *
     * @param majorName 专业名称
     * @return ID 值
     */
    default String selectIdByMajorName(String majorName) {
        LambdaQueryWrapper<Major> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Major::getMajorName, majorName);
        return Objects.requireNonNull(selectOne(wrapper),
                String.format("专业名称 %s 不存在", majorName)).getMajorId();
    }

}
